package com.syh.bishe.controller;


import com.syh.bishe.Util.UserHolder;
import com.syh.bishe.pojo.CarbonCredits;
import com.syh.bishe.pojo.Result;
import com.syh.bishe.service.ICarbonCreditsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author syh
 * @since 2024-07-02
 */
@Tag(name = "CarbonCreditsController", description = "公司碳额度模块")
@RestController
@RequestMapping("/carbon-credits")
@RequiredArgsConstructor
public class CarbonCreditsController {
    private final ICarbonCreditsService carbonCreditsService;
    @GetMapping("/getCreditAmount")
    @Operation(summary = "获取公司额度")
    public Result getCreditAmount() {
        BigDecimal creditAmount = carbonCreditsService.getCreditAmount(UserHolder.getUser().getCompanyId());
        return Result.success(creditAmount);
    }
    //公司余额获取
    @GetMapping("/getAccount")
    @Operation(summary = "获取公司余额")
    public Result getAccount() {
        BigDecimal creditAmount = carbonCreditsService.getAccount(UserHolder.getUser().getCompanyId());
        return Result.success(creditAmount);
    }
    //更新公司余额
    @PutMapping("/setAccount")
    @Operation(summary = "更新公司余额")
    public Result setAccount(@RequestBody CarbonCredits carbonCredits) {
        carbonCredits.setCompanyId(UserHolder.getUser().getCompanyId());
        carbonCreditsService.updateAccount(carbonCredits);
        return Result.success();
    }
}
